diff --git a/class-RegisterCSS.php b/class-RegisterCSS.php
index c18eb4e..96cda38 100644
--- a/class-RegisterCSS.php
+++ b/class-RegisterCSS.php
@@ -1,98 +1,92 @@
.
-class CSS {
- public $url;
- public $enqueue = false;
- public $enqueued = false;
-
- public function __construct($url) {
- $this->url = $url;
- }
-}
-
class RegisterCSS {
/**
* Stylesheets
*/
private $css = [];
/**
* Get the singleton instance
*
* @return self
*/
public function instance() {
static $me = false;
if( ! $me ) {
$me = new self();
}
return $me;
}
/**
- * Register a new style name.
+ * Register a new style name
*
* @param string $name CSS name, like: "jquery-ui".
* @param string $url CSS url, like "http://example.org/styles/jquery-ui.css".
- * @param boolean $private_use True: include it with $this->enqueueAll(); false: you have to include it manually. Use CSS::PRIVATE_USE instead of true for semantic reasons.
*/
- public function register($css_uid, $url) {
- $this->css[$css_uid] = new CSS($url);
+ public function register( $uid, $url ) {
+ $this->css[ $uid ] = new CSS( $url );
}
/**
- * Enqueue a previous registered CSS name.
+ * Enqueue a previous registered CSS name
*
- * @param string $css_uid CSS name.
+ * @param string $uid CSS name.
*/
- public function enqueue($css_uid) {
- if(!isset($this->css[$css_uid])) {
- DEBUG && error( sprintf(
- __("Il foglio di stile %s non può essere incorporato perchè non è stato ancora registrato."),
- "" . esc_html($css_uid) . ""
- ) );
+ public function enqueue( $uid ) {
+ if( empty( $this->css[ $uid ] ) ) {
+ error( "unknown stylesheet $uid" );
} else {
- $this->css[$css_uid]->enqueue = true;
- return true;
+ $this->css[ $uid ]->enqueue = true;
}
- return false;
}
/**
- * Enqueue all registered style that are not registered as private use.
+ * Enqueue all registered style that are not registered as private use
*/
- public function printAll($force = false) {
- foreach($this->css as $css_uid=>$css) {
- if($css->enqueue && !$css->enqueued) {
- self::link($css->url, $css_uid);
- $this->css[$css_uid]->enqueued = true;
+ public function printAll( $force = false ) {
+ foreach( $this->css as $uid => $css ) {
+ if( $css->enqueue && !$css->enqueued ) {
+ self::link( $css->url, $uid );
+ $this->css[ $uid ]->enqueued = true;
}
}
}
/**
- * Print the CSS link tag.
+ * Print the CSS link tag
*/
- public static function link($url, $css_uid) {
+ public static function link( $url, $uid ) {
if( CACHE_BUSTER ) {
- $url .= false === strpos($url, '?') ? '?' : '&';
+ $url .= false === strpos( $url, '?' ) ? '?' : '&';
$url .= CACHE_BUSTER;
}
- echo "\n\t";
+ echo "\n\t";
+ }
+}
+
+class CSS {
+ public $url;
+ public $enqueue = false;
+ public $enqueued = false;
+
+ public function __construct( $url ) {
+ $this->url = $url;
}
}
diff --git a/class-RegisterJS.php b/class-RegisterJS.php
index 212592d..159093e 100644
--- a/class-RegisterJS.php
+++ b/class-RegisterJS.php
@@ -1,130 +1,124 @@
.
/**
- * Classes useful to enqueue JS libraries.
+ * To enqueue JS libraries
*/
-class JS {
- const HEADER = true;
- const FOOTER = false;
-
- public $url;
- public $position = self::HEADER;
- public $enqueue = false;
-
- public function __construct($url) {
- $this->url = $url;
- }
-
- /**
- * @param boolean $in_head {JS::HEADER, JS::FOOTER}
- */
- public function enqueue($position = self::HEADER) {
- $this->position = self::filterPosition($position);
- $this->enqueue = true;
- }
-
- public static function filterPosition($position) {
- if( $position === null ) {
- return self::HEADER;
- }
- return $position;
- }
-}
-
class RegisterJS {
/**
- * Script names.
+ * Script names
*/
private $javascript = [];
- private $generated = [false, false];
+ private $generated = [ false, false ];
/**
* Get the singleton instance
*
* @return self
*/
public function instance() {
static $me = false;
if( ! $me ) {
$me = new self();
}
return $me;
}
/**
- * Register a new script name.
+ * Register a new script name
*
- * @param string $name JS name, like: "jquery".
- * @param string $url Script url, like "http://example.org/lib/jquery.js".
+ * @param string $name JS name, like: "jquery"
+ * @param string $url Script url, like "http://example.org/lib/jquery.js"
*/
- public function register($javascript_uid, $url) {
- if(isset($this->javascript[$javascript_uid])) {
- $this->javascript[$javascript_uid]->url = $url;
+ public function register( $uid, $url ) {
+ if( isset( $this->javascript[ $uid ] ) ) {
+ $this->javascript[ $uid ]->url = $url;
} else {
- $this->javascript[$javascript_uid] = new JS($url);
+ $this->javascript[ $uid ] = new JS( $url );
}
}
/**
- * Enqueue a previous registered JS name.
+ * Enqueue a previous registered JS name
*
- * @param string $name JS name.
- * @param bool $in_head Place it in the head of the page or not.
+ * @param string $name JS name
+ * @param bool $position Place it in the head of the page or not
*/
- public function enqueue($javascript_uid, $position = null) {
- $position = JS::filterPosition($position);
-
- if(isset($this->javascript[$javascript_uid])) {
- $this->javascript[$javascript_uid]->enqueue($position);
- return true;
+ public function enqueue( $uid, $position = null ) {
+ $position = JS::filterPosition( $position );
+ if( isset( $this->javascript[ $uid ] ) ) {
+ $this->javascript[ $uid ]->enqueue( $position );
} else {
- DEBUG && error( sprintf(
- __("La libreria JavaScript %s non può essere incorporata poichè non è ancora stata registrata."),
- "" . esc_html($javascript_uid) . ""
- ) );
- return false;
+ error( "unregistered JS $uid" );
}
}
- public function printAll($position) {
+ public function printAll( $position ) {
$cache_burster = CACHE_BUSTER;
- foreach($this->javascript as $javascript_uid=>$javascript) {
- if($javascript->enqueue && $javascript->position === $position) {
+ foreach( $this->javascript as $uid => $javascript ) {
+ if( $javascript->enqueue && $javascript->position === $position ) {
echo "\n";
- if($position === JS::HEADER) {
+ if( $position === JS::HEADER ) {
echo "\t";
}
$url = $javascript->url;
if( CACHE_BUSTER ) {
- $url .= false === strpos($url, '?') ? '?' : '&';
+ $url .= false === strpos( $url, '?' ) ? '?' : '&';
$url .= CACHE_BUSTER;
}
echo "";
- if(DEBUG) {
- echo "";
+ if( DEBUG ) {
+ echo "";
}
}
}
- $this->generated[(int) $position] = true;
+ $this->generated[ (int) $position ] = true;
}
- public function isGenerated($position) {
- return $this->generated[(int) $position];
+ public function isGenerated( $position ) {
+ return $this->generated[ (int) $position ];
+ }
+}
+
+class JS {
+ const HEADER = true;
+ const FOOTER = false;
+
+ public $url;
+ public $position = self::HEADER;
+ public $enqueue = false;
+
+ public function __construct( $url ) {
+ $this->url = $url;
+ }
+
+ /**
+ * @param boolean $in_head {JS::HEADER, JS::FOOTER}
+ */
+ public function enqueue( $position = self::HEADER ) {
+ $this->position = self::filterPosition( $position );
+ $this->enqueue = true;
+ }
+
+ public static function filterPosition( $position ) {
+ if( $position === null ) {
+ return self::HEADER;
+ }
+ return $position;
}
}